<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="getText()">点击获取数据</button>
    <div id="app"></div>
</body>
<script>
    function getText() {
        //1.创建对象
        let xmlHttp
        if (XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest()
        } else {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP')
        }
        console.log(xmlHttp.readyState, xmlHttp.status);

        //4.接收数据
        xmlHttp.onreadystatechange = function () {
            console.log(xmlHttp.readyState, xmlHttp.status);
            console.log(xmlHttp.response);
            app.innerHTML = xmlHttp.response
        }

        //2.打开链接
        xmlHttp.open('get', '../test.txt', true)

        //3.发送请求
        xmlHttp.send()
    }
</script>

</html>